package org.lgiavedoni.android.franq.command.general;

import org.apache.commons.cli.CommandLine;
import org.lgiavedoni.android.franq.core.command.Command;
import org.lgiavedoni.android.franq.core.envent.Event;
import org.lgiavedoni.android.franq.core.envent.dao.EventDao;
import org.lgiavedoni.android.franq.service.communication.CommunicationService;

public class HistoryCommand extends Command {

	@Override
	public boolean execute(CommandLine cmd) throws Exception {

		StringBuffer s = new StringBuffer();
		for (Event e : EventDao.inst.getLast(20)) {
			s.append(e.getCreationDateFormated() + " " + e + "\n");
		}
		CommunicationService.inst.sendDefaultTextMessage(s.toString());
		return true;
	}

	@Override
	public String getCommandText() {
		return "history";
	}
}